package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertFiledPartManufacturDO;
import cqrtplm.service.RtCertFiledPartManufacturService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 零件供应商控制器
 */
@RestController
@Api(tags = "认证-零件供应商")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/partmanufactur/" + "v1")
public class RtCertFiledPartManufacturController {

    @Resource
    private RtCertFiledPartManufacturService rtCertFiledPartManufacturService;

    /**
     * 查询零件供应商列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "list", notes = "获取零件供应商列表")
    public ResponseResult list(@RequestBody RtCertFiledPartManufacturDO rtCertFiledPartManufactur) {
        List<RtCertFiledPartManufacturDO> list = rtCertFiledPartManufacturService.selectRtCertFiledPartManufacturList(rtCertFiledPartManufactur);
        return ResponseResult.success(list);
    }

    /**
     * 分页查询零件供应商列表
     */
    @PostMapping("/pagelist")
    @ApiOperation(value = "pagelist", notes = "分页获取零件供应商列表")
    public ResponseResult<PageInfo<RtCertFiledPartManufacturDO>> pagelist(
            @RequestBody RtCertFiledPartManufacturDO rtCertFiledPartManufactur,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertFiledPartManufacturDO> list = rtCertFiledPartManufacturService.selectRtCertFiledPartManufacturList(rtCertFiledPartManufactur);
        PageInfo<RtCertFiledPartManufacturDO> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    /**
     * 导出零件供应商列表
     */
    @PostMapping("/export")
    @ApiOperation(value = "export", notes = "导出零件供应商列表")
    public void export(HttpServletResponse response, RtCertFiledPartManufacturDO rtCertFiledPartManufactur) {
        List<RtCertFiledPartManufacturDO> list = rtCertFiledPartManufacturService.selectRtCertFiledPartManufacturList(rtCertFiledPartManufactur);
        // ExcelUtil.listToExcel(list, RtCertFiledPartManufacturDO.class, wwb, "零件供应商数据");
    }

    /**
     * 获取零件供应商详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "getInfo", notes = "获取零件供应商详情")
    public ResponseResult getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(rtCertFiledPartManufacturService.selectRtCertFiledPartManufacturById(id));
    }

    /**
     * 根据零件ID获取零件供应商
     */
    @GetMapping("/part/{partId}")
    @ApiOperation(value = "getByPartId", notes = "根据零件ID获取零件供应商")
    public ResponseResult getByPartId(@PathVariable("partId") String partId) {
        return ResponseResult.success(rtCertFiledPartManufacturService.selectRtCertFiledPartManufacturByPartId(partId));
    }

    /**
     * 新增零件供应商
     */
    @PostMapping("/add")
    @ApiOperation(value = "add", notes = "新增零件供应商")
    public ResponseResult add(@RequestBody RtCertFiledPartManufacturDO rtCertFiledPartManufactur) {
        return ResponseResult.success(rtCertFiledPartManufacturService.insertRtCertFiledPartManufactur(rtCertFiledPartManufactur));
    }

    /**
     * 修改零件供应商
     */
    @PostMapping("/edit")
    @ApiOperation(value = "edit", notes = "修改零件供应商")
    public ResponseResult edit(@RequestBody RtCertFiledPartManufacturDO rtCertFiledPartManufactur) {
        return ResponseResult.success(rtCertFiledPartManufacturService.updateRtCertFiledPartManufactur(rtCertFiledPartManufactur));
    }

    /**
     * 删除零件供应商
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "delete", notes = "删除零件供应商")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertFiledPartManufacturService.deleteRtCertFiledPartManufacturByIds(ids));
    }
}
